package com.app.biz.controller.formal;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.app.common.core.page.TableDataInfo;
import com.app.common.utils.poi.ExcelUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.app.common.annotation.Log;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.AjaxResult;
import com.app.common.enums.BusinessType;
import com.app.biz.domain.formal.BizProduceSaleFormal;
import com.app.biz.service.IBizProduceSaleFormalService;


/**
 * 重点地区产销率完成情况Controller
 * 
 * @author Zhou_S
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/sale/saleformal")
public class BizProduceSaleFormalController extends BaseController
{
    @Autowired
    private IBizProduceSaleFormalService bizProduceSaleFormalService;

    /**
     * 查询重点地区产销率完成情况列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizProduceSaleFormal bizProduceSaleFormal)
    {
        if(StringUtils.isNotBlank(bizProduceSaleFormal.getDates())){
            DateTime datesTimes= DateUtil.parse(bizProduceSaleFormal.getDates(),"yyyy年MM月");
            bizProduceSaleFormal.setDates(DateUtil.format(datesTimes,"yyyy-MM"));
        }else{
            AjaxResult.warn("未指定日期！");
        }
        startPage();
        List<BizProduceSaleFormal> list = bizProduceSaleFormalService.selectBizProduceSaleFormalList(bizProduceSaleFormal);
        return getDataTable(list);
    }

    /**
     * 导出重点地区产销率完成情况列表
     */
    @PreAuthorize("@ss.hasPermi('sale:saleformal:export')")
    @Log(title = "重点地区产销率完成情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizProduceSaleFormal bizProduceSaleFormal)
    {
        List<BizProduceSaleFormal> list = bizProduceSaleFormalService.selectBizProduceSaleFormalList(bizProduceSaleFormal);
        ExcelUtil<BizProduceSaleFormal> util = new ExcelUtil<BizProduceSaleFormal>(BizProduceSaleFormal.class);
        util.exportExcel(response, list, "重点地区产销率完成情况数据");
    }

    /**
     * 获取重点地区产销率完成情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:saleformal:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizProduceSaleFormalService.selectBizProduceSaleFormalByBaseId(baseId));
    }

    /**
     * 新增重点地区产销率完成情况
     */
    @PreAuthorize("@ss.hasPermi('sale:saleformal:add')")
    @Log(title = "重点地区产销率完成情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProduceSaleFormal bizProduceSaleFormal)
    {
        return toAjax(bizProduceSaleFormalService.insertBizProduceSaleFormal(bizProduceSaleFormal));
    }

    /**
     * 修改重点地区产销率完成情况
     */
    @PreAuthorize("@ss.hasPermi('sale:saleformal:edit')")
    @Log(title = "重点地区产销率完成情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProduceSaleFormal bizProduceSaleFormal)
    {
        return toAjax(bizProduceSaleFormalService.updateBizProduceSaleFormal(bizProduceSaleFormal));
    }

    /**
     * 删除重点地区产销率完成情况
     */
    @PreAuthorize("@ss.hasPermi('sale:saleformal:remove')")
    @Log(title = "重点地区产销率完成情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(bizProduceSaleFormalService.deleteBizProduceSaleFormalByBaseIds(baseIds));
    }
}
